package com.zhisheng.controller;

import com.zhisheng.pojo.Emp;
import com.zhisheng.pojo.MyResponseResult;
import com.zhisheng.pojo.PageBean;
import com.zhisheng.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 员工管理Controller
 */
@RestController
@RequestMapping("emps")
public class EmpController {

    @Autowired
    private EmpService empService;

    @GetMapping // 目前只有分页,没有带条件
    public MyResponseResult<PageBean<Emp>> getByPage(Integer page,Integer pageSize){
        // 参  调  响
        PageBean<Emp> pageBean = empService.getByPage(page, pageSize);
        return MyResponseResult.ok(pageBean);
    }
    @PostMapping("/save")
    public MyResponseResult<Object> saveEmp(@RequestBody Emp emp){
        // 参 调  响
        int i = empService.insert(emp);
        return i>=1?MyResponseResult.ok(emp.getId()):MyResponseResult.error("添加:"+emp.getName()+" 失败!");
    }
    @PostMapping("/update")
    public MyResponseResult<Object> updateEmp(@RequestBody Emp emp){
        // 参 调  响
        int i = empService.update(emp);
        return i>=1?MyResponseResult.ok(emp.getId()):MyResponseResult.error("修改:"+emp.getId()+" 失败!");
    }

}
